fix(vue): Prevent TDZ error in watch callbacks#7743
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: c664395 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughAdds a changeset for a patch release to the 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/vue/src/composables/useOrganization.ts (1)
59-71:⚠️ Potential issue | 🟠 MajorBump Vue peer dependency or replace
{ once: true }with manual unwatch in useOrganization, useSignIn, and useSignUp.The
onceoption forwatch()was introduced in Vue 3.4, butpackages/vue/package.jsonspecifies"vue": "^3.2.0". Users on Vue 3.2 or 3.3 will not get the intended one-shot behavior. Either bump the peer dependency to"^3.4.0"or switch to the manual unwatch pattern already used elsewhere in the codebase (e.g.,useClerkLoaded.tsanduseAuth.ts).
| let unwatch: (() => void) | undefined; | ||
| // eslint-disable-next-line prefer-const | ||
| unwatch = watch( | ||
| clerk, | ||
| unwrappedClerk => { | ||
| if (!unwrappedClerk?.loaded) { | ||
| return; | ||
| } | ||
|
|
||
| callback(unwrappedClerk as LoadedClerk); | ||
| unwatch?.(); | ||
| }, | ||
| { immediate: true }, |
There was a problem hiding this comment.
We are not using the once option here as we also need to wait for the loaded value of Clerk to be true and the once option will stop the watcher once clerk has a value
| watch( | ||
| clerk, | ||
| value => { | ||
| if (value) { | ||
| value.telemetry?.record(eventMethodCalled('useSignIn')); | ||
| } | ||
| }, | ||
| { once: true }, | ||
| ); |
There was a problem hiding this comment.
Q: Why not use the useClerkLoaded helper?
A: Telemetry can be recorded as soon as the clerk instance exists. We don't have to wait for Clerk to be loaded
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Description
This PR fixes an error occurring in Vue composables where watchers attempted to call
unwatch()within their own initialization.Fixes https://discord.com/channels/856971667393609759/1468208882378739765
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit